﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using WMS6.Web.LoginServiceRef;

    public class LoginServiceClientProxy : BasePage
    {
        public string CheckIsVendorExist(string userID, string type)
        {
            string result = string.Empty;
            LoginServiceClient client = new LoginServiceClient("WSHttpBinding_ILoginService");
            try
            {
                PubParasInfo pubParasInfo = new PubParasInfo {
                    CurrentWH = "10",
                    UserID = userID,
                    UserLanguage = "zh-cn"
                };
                result = client.CheckIsVendorExist(userID, type, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public List<GlobalSettingInfo> GetALLGlobalSetting()
        {
            List<GlobalSettingInfo> globalSettingInfoList = null;
            LoginServiceClient client = new LoginServiceClient("WSHttpBinding_ILoginService");
            try
            {
                globalSettingInfoList = client.GetALLGlobalSetting();
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return globalSettingInfoList;
        }

        public static LoginServiceClientProxy GetInstance()
        {
            return new LoginServiceClientProxy();
        }

        public PreferenceProfileInfo GetPreferenceProfileByUserID(string userID)
        {
            PreferenceProfileInfo preferenceProfileInfo = null;
            LoginServiceClient client = new LoginServiceClient("WSHttpBinding_ILoginService");
            try
            {
                preferenceProfileInfo = client.GetPreferenceProfileByUserID(userID);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return preferenceProfileInfo;
        }

        public UserMstInfo GetUserInfoByID(string userID)
        {
            UserMstInfo userMstInfo = null;
            LoginServiceClient client = new LoginServiceClient("WSHttpBinding_ILoginService");
            try
            {
                userMstInfo = client.GetUserInfoByID(userID);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return userMstInfo;
        }

        public string InsertUserPreference(PreferenceProfileInfo preferencePrifile)
        {
            string result = string.Empty;
            LoginServiceClient client = new LoginServiceClient("WSHttpBinding_ILoginService");
            try
            {
                result = client.InsertUserPreference(preferencePrifile);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateGlobalSetting(GlobalSettingInfo globalSettingInfo)
        {
            string result = string.Empty;
            LoginServiceClient client = new LoginServiceClient("WSHttpBinding_ILoginService");
            try
            {
                result = client.UpdateGlobalSetting(globalSettingInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public void WriteLoginLog(SysLoginLogInfo sysLoginLog)
        {
            LoginServiceClient client = new LoginServiceClient("WSHttpBinding_ILoginService");
            try
            {
                client.InsertSysLoginLogInfo(sysLoginLog);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
        }
    }
}

